<?
include ("../php/conni.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="../js/json2.js"></script>
<script type="text/javascript" src="../js/pub.js"></script>

<link href="../css/pub.css" rel="stylesheet" type="text/css" />

<link href="../css/change_password.css" rel="stylesheet" type="text/css" />


<body>
		<?
		if($_POST[item]==''||!$_POST[item]||$_POST[item]=="back")
		{
		?>
		<form action="" method="post">
		<input type="hidden" name="item" value="change_password">
		<div class="c_body">
			<div class="c_l">
				<div class="c_1">
					旧密码：
				</div>
				<div class="c_2">
					<input type="password" class="pub_text_1 ct1" name="o_pwd" >
				</div>
			</div>
			<div class="c_l">
				
				<div class="c_1">
					新密码：
				</div>
				<div class="c_2">
					<input type="password" class="pub_text_1 ct1" name="n_pwd">
				</div>
				
			</div>
			<div class="c_l">
				
				<div class="c_1">
					确认新密码：
				</div>
				<div class="c_2">
					<input type="password" class="pub_text_1 ct1" name="rn_pwd">
				</div>
			</div>
			<div class="c_l">
				
				<div class="c_3" >
					<input type="submit" value="提交" class="c_button">
				</div>
				
			</div>
		</div>
		</form>
		<?
		}
		else if($_POST[item]=='change_password')
		{
			if($_POST[o_pwd]!=''&&$_POST[n_pwd]!=''&&$_POST[rn_pwd]!='')
			{
				if($_POST[rn_pwd]!==$_POST[n_pwd])
				{

					?>
					<form action="" method="post">
					<input type="hidden" name="item" value="back">
					<div class="c_body">
						<div class="c_l">
							<div class="c_3">
								新密码与确认新密码不一致
							</div>
							
						</div>
						
						<div class="c_l">
							
							<div class="c_3" >
								<input type="submit" value="返回" class="c_button">
							</div>
							
						</div>
					</div>
					</form>
					<?

				}
				else if($_POST[rn_pwd]==$_POST[n_pwd])
				{
					$query="select * from user where id='".$_SESSION['user_id']."'";
					if($result=$conni->query($query))
					{
						$row=$result->fetch_assoc();
						if($row[passwd]==$_POST[o_pwd])
						{
							$query="UPDATE user SET passwd = '".$_POST[n_pwd]."' WHERE id ='".$_SESSION['user_id']."' ";
							if($result=$conni->query($query))
							{
								?>
								<div class="c_body">
									<div class="c_l">
										<div class="c_3">
											密码修改成功
										</div>
									</div>
								</div>
								<?
							}
						}
						else
						{
						?>
						<form action="" method="post">
						<input type="hidden" name="item" value="back">
						<div class="c_body">
							<div class="c_l">
								<div class="c_3">
									旧密码不正确
								</div>
								
							</div>
							
							<div class="c_l">
								
								<div class="c_3" >
									<input type="submit" value="返回" class="c_button">
								</div>
								
							</div>
						</div>
						</form>
						<?

						}
					}
				}
			}
			else
			{
				?>
					<form action="" method="post">
					<input type="hidden" name="item" value="back">
					<div class="c_body">
						<div class="c_l">
							<div class="c_3">
								旧密码、新密码、确认新密码均不能为空
							</div>
							
						</div>
						
						<div class="c_l">
							
							<div class="c_3" >
								<input type="submit" value="返回" class="c_button">
							</div>
							
						</div>
					</div>
					</form>
				<?
			}
		}

		?>
</body>
</html>